package com.vcredit.creditcat.service;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.ChannelStatisticsConfigExternal_AD;
import com.vcredit.creditcat.vo.ChannelStatisticsConfigExternalVo;
import com.vcredit.creditcat.framework.pagination.Criteria;
import com.vcredit.creditcat.framework.pagination.Page;
import com.vcredit.creditcat.persistence.base.ChannelStatisticsConfigExternalMapper;
import com.vcredit.framework.util.BeanUtil;

 /*
  * @author zhangxingong
  * @version 1.0
  * @since 1.0
 */
@Service
public class ChannelStatisticsConfigExternalService {
    
    @Autowired
	private ChannelStatisticsConfigExternalMapper channelStatisticsConfigExternalMapper;
    
	public Page<ChannelStatisticsConfigExternal_AD> findByPage(Criteria criteria){
	    return new Page<ChannelStatisticsConfigExternal_AD>(channelStatisticsConfigExternalMapper.findByPageCount(criteria), channelStatisticsConfigExternalMapper.findByPage(criteria));
	}
	
	public List<ChannelStatisticsConfigExternal_AD> find(ChannelStatisticsConfigExternal_AD channelStatisticsConfigExternal){
	    return channelStatisticsConfigExternalMapper.find(channelStatisticsConfigExternal);
	}
	
	public ChannelStatisticsConfigExternal_AD findById(Long channelId){
	    return channelStatisticsConfigExternalMapper.findById(channelId);
	}
	
	public List<ChannelStatisticsConfigExternal_AD> findAll(){
	    return channelStatisticsConfigExternalMapper.findAll();
	}
	
	public void save(ChannelStatisticsConfigExternalVo channelStatisticsConfigExternalVo){
	  try {
		  ChannelStatisticsConfigExternal_AD channelStatisticsConfigExternal = new ChannelStatisticsConfigExternal_AD();
	     BeanUtil.copy(channelStatisticsConfigExternalVo, channelStatisticsConfigExternal);
	     channelStatisticsConfigExternalMapper.insert(channelStatisticsConfigExternal);
       }catch (Exception e) {
           e.printStackTrace();
       }
	}
	
	public void update(ChannelStatisticsConfigExternal_AD channelStatisticsConfigExternal){
		channelStatisticsConfigExternalMapper.update(channelStatisticsConfigExternal);
	}
	
	public void removeChannelStatisticsConfigExternal(String ids){
	  for (String channelIdString : ids.split(",")) {
        Long channelId = Long.parseLong(channelIdString);
        channelStatisticsConfigExternalMapper.delete(channelId);
      }
	}
	
}
